<template>
  <div class="app-container">

    <el-dialog title="经验值明细" :visible.sync="open" width="60%" append-to-body>
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px">
      <!-- 1.圈子签到，
2关注圈子
3任务奖励
4.圈子登记升级礼包
5不定期的荧光棒活动
6月卡福利 
0管理员修改 -->
      <el-form-item label="荧光棒来源" prop="type">
        <el-select v-model="queryParams.type" clearable size="small">
          <el-option label="圈子签到" :value="1" />
          <el-option label="关注圈子" :value="2" />
          <el-option label="任务奖励" :value="3" />
          <el-option label="圈子登记升级礼包" :value="4" />
          <el-option label="不定期的荧光棒活动" :value="5" />
          <el-option label="月卡福利 " :value="6" />
          <el-option label="管理员修改 " :value="0" />
        </el-select>
      </el-form-item>
      <el-form-item label="操作时间" prop="changeTime">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.changeTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="操作时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="userLightStackList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="id" align="center" prop="id" /> -->
      <el-table-column label="荧光棒来源" align="center" prop="type" >
        <template slot-scope="scope">
          <span v-if="scope.row.type===1">圈子签到</span>
          <span v-else-if="scope.row.type===2">关注圈子</span>
          <span v-else-if="scope.row.type===3">任务奖励</span>
          <span v-else-if="scope.row.type===4">圈子登记升级礼包</span>
          <span v-else-if="scope.row.type===5">不定期的荧光棒活动</span>
          <span v-else-if="scope.row.type===6">月卡福利</span>
          <span v-else-if="scope.row.type===0">管理员修改</span>
          <span v-else>未知</span>
        </template>
      </el-table-column>
      <el-table-column label="荧光棒变化" align="center" prop="sroce" />
      <el-table-column label="当前荧光棒值" align="center" prop="currentSroce" />
      <el-table-column label="时间" align="center" prop="changeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.changeTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remarks" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-dialog>
  </div>
</template>

<script>
import { listUserLightStack, getUserLightStack, delUserLightStack, addUserLightStack, updateUserLightStack, exportUserLightStack } from "@/api/system/userLightStack";

export default {
  name: "UserLightStack",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 账号荧光棒明细表格数据
      userLightStackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: undefined,
        changeTime: undefined,
      },
      userData: {}
    };
  },
  created() {
  },
  methods: {
    init(row){
      this.getList()
      this.open = true
      this.userData = row
    },
    /** 查询账号荧光棒明细列表 */
    getList() {
      this.loading = true;
      listUserLightStack(this.queryParams).then(response => {
        this.userLightStackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有账号荧光棒明细数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportUserLightStack(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>